package stream;

import com.sun.org.apache.regexp.internal.RE;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public class Demo1 {
    public static void main(String[] args) {
        User u1 = new User(1,"u1",11);
        User u2 = new User(2,"u2",12);
        User u3 = new User(3,"u3",13);
        User u4 = new User(4,"u4",14);
        User u5 = new User(5,"u5",15);

        //list集合存储这些User对象
        List<User> list = Arrays.asList(u1,u2,u3,u4,u5);

        //筛选
        list.stream()
                .filter((t)->t.getId()%2==0)
                .filter((t)->t.getAge()>11)
                .map(t->{
                    t.setName(t.getName().toUpperCase(Locale.ROOT));
                    return t;
                })
                .sorted(Comparator.comparing(User::getId).reversed())
                .limit(2)
                .forEach((t)-> System.out.println(t.getId()+"=="+t.getName()+"=="+t.getAge()));

    }
}
